package worker

import (
	"GraduationProject/public/db"
	"GraduationProject/public/models"
	"GraduationProject/webserver/controllers/util"
	"github.com/gin-gonic/gin"
)

func Workers(c *gin.Context) {
	_, err := util.AdminFilter(c)
	if err != nil {
		return
	}

	var count int
	db.DB.Model(&models.Worker{}).Count(&count)
	var workers []models.Worker
	db.DB.Limit(c.PostForm("limit")).Preload("Machine").
		Offset(c.PostForm("offset")).Find(&workers)

	c.JSON(200, gin.H{
		"status":  10000,
		"message": "success",
		"workers": workers,
		"count":   count,
	})
}
